<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>地图导航</title>
    <style>
        *{
            margin:0;
            padding:0;
        }

        #container{
            width:100%;
            height:100vh;
            background-color:pink;
        }
    </style>
</head>
<body>
<div id="container"></div>
<script type="text/javascript">
    window._AMapSecurityConfig = {
      securityJsCode: "8705f3371528b0829c79975edf5be776",
    };
</script>
<script
        type="text/javascript"
        src="https://webapi.amap.com/maps?v=2.0&key=b6910dafe39d58bc89014963364b01a9"
></script>
<script type="text/javascript">
    //地图初始化应该在地图容器div已经添加到DOM树之后
    var zoom = 20
    var map = new AMap.Map("container", {
      zoom: zoom,
      center:[113.685473,34.772285] ,//地图中心点坐标
    });

    //定义定位的方法
    function setLocation(lon, lat){
        map.setZoomAndCenter(zoom, [lon, lat]) //设置中心的位置

        //设置当前位置的标记
        var marker = new AMap.Marker({
            map: map,
            icon: "https://webapi.amap.com/theme/v1.3/markers/n/mark_b.png",
            position: [lon, lat]
        });
        map.add(marker)

        map.plugin(['AMap.PlaceSearch'], function() {
            var PlaceSearchOptions = { //设置PlaceSearch属性
                map:map,              //在地图当中显示对应的标记
                pageSize: 4,           //每页结果数,默认10
                pageIndex: 1,          //请求页码，默认1
                extensions: "base"     //返回信息详略，默认为base（基本信息）
            };
            var MSearch = new AMap.PlaceSearch(PlaceSearchOptions); //构造PlaceSearch类
            AMap.Event.addListener(MSearch, "complete", (result)=>{
                //网页中调用鸿蒙端的方法，现在最近的几个地址
                //window.swift.alert(JSON.stringify(result.poiList.pois))
                window.swift.receiveNearPlace(JSON.stringify(result.poiList.pois))
            }); //返回结果
            MSearch.searchNearBy("停车场",[lon, lat]);     //关键字查询
        });
    }

    window.onload=function(){
        //调用鸿蒙端的业务方法
        window.swift.setCurrentLocation()
    }
</script>
</body>
</html>